/*******************************************************************************
 * Copyright (c) 2010, 2030 www.itlaobing.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package cn.itlaobing.dao;/**
 * Created by asus-pc on 2017/11/10 0010.
 */

import cn.itlaobing.model.TrainModel;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: TrainDao <br/>
 * Function: TODO 功能描述 <br/>
 * date: 2017/11/10 0010 9:28 <br/>
 *
 * @author SCAR、
 * @since JDK 1.8
 */
public class TrainDao extends BaseDao {
    public List<TrainModel> findTrain(String trainnum,String startsta,String endsta)throws SQLException{
        QueryRunner qr= new QueryRunner(getDataSource());
        String sql="SELECT t1.trainNum trainNum,t1.station startStation,t2.station endStation,ABS(t2.sitePrice-t1.sitePrice) sitePrice FROM " +
                "(SELECT * FROM station WHERE station = ? AND trainNum=? )t1, " +
                "(SELECT * FROM station WHERE station = ? AND trainNum=?)t2 ";
        BeanListHandler<TrainModel> beanListHandler =new BeanListHandler<TrainModel>(TrainModel.class);

        List<TrainModel> list= qr.query(sql,beanListHandler,startsta,trainnum,endsta,trainnum);

        return list;

    }

}
